import type { Module, ActionContext } from 'vuex'
import type { AxiosResponse } from 'axios'
import type { singleLampStateType } from './typings'
import {
  deviceListGet,
  deviceAdd,
  deviceUpdate,
  getModelList,
  // selectBoxListByName,
  deviceRemove,
  deviceView,
  deviceSimpleMes,
  saveParamSet,
  sendParamSet,
  singlelampDim,
  singlelampSwitch,
  singlelampDimLoop,
  // deviceExport,
  groupList,
  groupAdd,
  groupUpdate,
  groupDelete,
  groupData,
  lamppostList,
  lamppostAdd,
  lamppostUpdate,
  lamppostDelete,
  syncLamppost,
  changeGroup,
  getsingleLampBykeyword,
  getSingleLampAndpost,
  lamppostBindLamp,
  taskList,
  taskAdd,
  taskUpdate,
  taskDelete,
  taskDetail,
  callLampPlan,
  getTaskDeviceListPage,
  sendTask,
  lampAlarmPage,
  lampAlarmUpdate,
  getPostTree,
  getPostPositionData,
  getPostDetail,
  lamppostPoll,
  lamppostSwitch,
  lamppostdim,
  updateGroup,
  groupSwitchLight,
  groupDim,
  dayEnergyData,
  dayDimData,
  energyData,
  callLampWorkData,
  callLampTime,
  lampNodeCleanProtect,
  lampResetting,
  lampNodeTimeSyncSet,
  getWorkData,
  exportWorkData,
  alarmlistPage,
  importLampExcel,
  importLampPostExcel,
  exportLampPost,
  exportLamp
} from '~/api/monitor/singleLamp'
import { getDataDictionaryByCode } from '~/api/global'
import { filterValueEnum, DownloadAttachment } from '~/utils/util'

const singleLamp: Module<singleLampStateType, singleLampStateType> = {
  namespaced: true,
  state: {
    communicationStateOpt: [], // 通讯状态
    communicationStateEnum: {},
    devBrand: [], // 设备品牌
    devModel: [], // 设备型号
    alarmLevelOpt: [],
    alarmLevelNum: {},
    alarmTypeOpt: [],
    alarmTypeNum: {},
    runStatusOpt: [],
    runStatusNum: {}
  },
  getters: {
    communicationStateOpt: (state) => state.communicationStateOpt,
    communicationStateEnum: (state) => state.communicationStateEnum,
    runStatus: (state) => state.runStatus,
    devBrand: (state) => state.devBrand,
    devModel: (state) => state.devModel,
    alarmLevelOpt: (state) => state.alarmLevelOpt,
    alarmLevelNum: (state) => state.alarmLevelNum,
    alarmTypeOpt: (state) => state.alarmTypeOpt,
    alarmTypeNum: (state) => state.alarmTypeNum,
    runStatusOpt: (state) => state.runStatusOpt,
    runStatusNum: (state) => state.runStatusNum
  },
  mutations: {
    SET_LINE(state, payload) {
      state.communicationStateOpt = payload
      state.communicationStateEnum = filterValueEnum(payload, 'dictKey', 'dictValue')
    },
    SET_RUNSTATUS(state, payload) {
      state.runStatusOpt = payload
      state.runStatusNum = filterValueEnum(payload, 'dictKey', 'dictValue')
    },
    SET_DEVBRAND(state, payload) {
      state.devBrand = payload
    },
    SET_DEVMODEL(state, payload) {
      state.devModel = payload
    },
    SET_ALARMLEVEL(state, payload) {
      state.alarmLevelOpt = payload
      state.alarmLevelNum = filterValueEnum(payload, 'dictKey', 'dictValue')
    },
    SET_ALARMTYPE(state, payload) {
      state.alarmTypeOpt = payload
      state.alarmTypeNum = filterValueEnum(payload, 'dictKey', 'dictValue')
    }
  },
  actions: {
    // 单灯型号
    GetModelList<S, T>({ commit }: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getModelList<T>(params)
          .then((res: AxiosResponse) => {
            const arr: any = []
            for (const item in res?.data?.data) {
              arr.push({
                id: item,
                name: res?.data?.data[item]
              })
            }
            commit('SET_DEVMODEL', arr)
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    //  单灯-列表
    DeviceListGet<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deviceListGet<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    //  单灯-详情
    DeviceView<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deviceView<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯-参数设置
    SaveParamSet<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        saveParamSet<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯-下发参数
    SendParamSet<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        sendParamSet<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯-调光
    SinglelampDim<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        singlelampDim<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯-调光按位
    SinglelampDimLoop<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        singlelampDimLoop<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯-开关灯
    SinglelampSwitch<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        singlelampSwitch<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    //  单灯-删除
    DeviceRemove<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deviceRemove<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    //  单灯-编辑
    DeviceUpdate<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deviceUpdate<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯简略信息
    DeviceSimpleMes<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deviceSimpleMes<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    //  单灯-新增
    DeviceAdd<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        deviceAdd<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯-导出
    // async DeviceExport<S, T>(_: ActionContext<S, T>, params: T) {
    //   return await deviceExport<T>(params).then((res: AxiosResponse) => {
    //     const contentDisposition = res?.headers?.['content-disposition']
    //     if (contentDisposition && res.data) {
    //       DownloadAttachment(decodeURI(contentDisposition.substring(20)), res.data)
    //     }
    //     return res.data
    //   })
    // },
    // 在线状态
    CommunicationStateGet<S, T>({ commit }: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getDataDictionaryByCode<T>(params)
          .then((res: AxiosResponse) => {
            commit('SET_LINE', res?.data?.data || [])
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 故障状态
    RunstatusStateGet<S, T>({ commit }: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getDataDictionaryByCode<T>(params)
          .then((res: AxiosResponse) => {
            commit('SET_RUNSTATUS', res?.data?.data || [])
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 设备型号
    DevModleStateGet<S, T>({ commit }: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getDataDictionaryByCode<T>(params)
          .then((res: AxiosResponse) => {
            commit('SET_DEVMODEL', res?.data?.data || [])
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 警报等级
    AlarmLevelGet<S, T>({ commit }: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getDataDictionaryByCode<T>(params)
          .then((res: AxiosResponse) => {
            commit('SET_ALARMLEVEL', res?.data?.data || [])
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 警报类型
    AlarmTypeGet<S, T>({ commit }: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getDataDictionaryByCode<T>(params)
          .then((res: AxiosResponse) => {
            commit('SET_ALARMTYPE', res?.data?.data || [])
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯分组 - 分页
    GroupList<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupList<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯分组 - 新增
    GroupAdd<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupAdd<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯分组 - 编辑
    GroupUpdate<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupUpdate<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯分组 - 删除
    GroupDelete<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupDelete<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯分组 - 列表
    GroupData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 灯杆列表 - 分页
    LamppostList<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostList<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 灯杆列表 - 新增
    LamppostAdd<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostAdd<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 灯杆列表 - 编辑
    LamppostUpdate<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostUpdate<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 灯杆列表 - 删除
    LamppostDelete<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostDelete<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 灯杆列表 - 同步资产
    SyncLamppost<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        syncLamppost<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 灯杆列表-批量修改灯杆分组
    ChangeGroup<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        changeGroup<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 关键字搜索单灯
    GetsingleLampBykeyword<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getsingleLampBykeyword<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 绑定单灯
    LamppostBindLamp<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostBindLamp<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 获取灯杆关联单灯
    GetSingleLampAndpost<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getSingleLampAndpost<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略 - 分页
    TaskList<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        taskList<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略 - 新增
    TaskAdd<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        taskAdd<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略 - 编辑
    TaskUpdate<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        taskUpdate<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略 - 删除
    TaskDelete<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        taskDelete<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略 - 详情
    TaskDetail<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        taskDetail<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略 - 召测计划
    CallLampPlan<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        callLampPlan<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯策略-任务设备明细
    GetTaskDeviceListPage<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getTaskDeviceListPage<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 下发策略
    SendTask<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        sendTask<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯警报设置 - 分页
    LampAlarmPage<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lampAlarmPage<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯警报设置 - 修改
    LampAlarmUpdate<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lampAlarmUpdate<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 查询灯杆树
    GetPostTree<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getPostTree<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 查询灯杆点位数据
    GetPostPositionData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getPostPositionData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 查询灯杆详情
    GetPostDetail<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getPostDetail<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 灯杆召测
    LamppostPoll<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostPoll<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 灯杆开关灯
    LamppostSwitch<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostSwitch<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 灯杆调光
    Lamppostdim<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lamppostdim<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 灯杆更换分组
    UpdateGroup<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        updateGroup<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 分组批量开关灯
    GroupSwitchLight<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupSwitchLight<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 分组批量调光
    GroupDim<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        groupDim<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 查询灯杆当日实时统计数据
    DayEnergyData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        dayEnergyData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 查询当日灯杆24小时调光曲线图
    DayDimData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        dayDimData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 查询当日灯杆24小时能耗曲线图
    EnergyData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        energyData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 单灯召测工况
    CallLampWorkData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        callLampWorkData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 单灯召测时钟
    CallLampTime<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        callLampTime<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 单灯解除漏电保护
    LampNodeCleanProtect<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lampNodeCleanProtect<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 单灯复位
    LampResetting<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lampResetting<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 运行地图 - 设备校时
    LampNodeTimeSyncSet<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        lampNodeTimeSyncSet<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯工况 - 分页
    GetWorkData<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        getWorkData<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯工况 - 导出
    async ExportWorkData<S, T>(_: ActionContext<S, T>, params: T) {
      return await exportWorkData<T>(params).then((res: AxiosResponse) => {
        const contentDisposition = res?.headers?.['content-disposition']
        if (contentDisposition && res.data) {
          DownloadAttachment(decodeURI(contentDisposition.substring(20)), res.data)
        }
        return res.data
      })
    },
    // 单灯警报列表 - 分页
    AlarmlistPage<S, T>(_: ActionContext<S, T>, params: T) {
      return new Promise((resolve, reject) => {
        alarmlistPage<T>(params)
          .then((res: AxiosResponse) => {
            resolve(res.data)
          })
          .catch((err: AxiosResponse) => {
            reject(err)
          })
      })
    },
    // 单灯设备-导入
    async ImportLampExcel<S, T>(_: ActionContext<S, T>, params: T) {
      return await importLampExcel<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 单灯灯杆-导入
    async ImportLampPostExcel<S, T>(_: ActionContext<S, T>, params: T) {
      return await importLampPostExcel<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 下载单灯灯杆模版
    async ExportLampPost<S, T>(_: ActionContext<S, T>, params: T) {
      return await exportLampPost<T>(params).then((res: AxiosResponse) => {
        const contentDisposition = res?.headers?.['content-disposition']
        if (contentDisposition && res.data) {
          DownloadAttachment(decodeURI(contentDisposition.substring(20)), res.data)
        }
        return res.data
      })
    },
    // 下载单灯设备模版
    async ExportLamp<S, T>(_: ActionContext<S, T>, params: T) {
      return await exportLamp<T>(params).then((res: AxiosResponse) => {
        const contentDisposition = res?.headers?.['content-disposition']
        if (contentDisposition && res.data) {
          DownloadAttachment(decodeURI(contentDisposition.substring(20)), res.data)
        }
        return res.data
      })
    }
  }
}

export default singleLamp
